package WinterVacation.Day12;

public class Num58 {
    public static int lengthOfLastWord(String s) {
        char[] arr = s.toCharArray();
        int lastLength = 0;
        for (int i = arr.length - 1; i >= 0; i--) {
            if(arr[i] != ' '){
                lastLength++;
            }
            if(lastLength != 0 && arr[i] == ' '){
                break;
            }
        }
        return lastLength;
    }

    public static void main(String[] args) {
        String s = "   fly me   to   the moon  ";
        System.out.println(lengthOfLastWord(s));
    }
}
